package com.jfirer.redisserver;

import com.jfirer.jnet.common.api.ProcessorContext;
import com.jfirer.jnet.common.api.WriteProcessor;
import com.jfirer.jnet.common.buffer.BufferAllocator;
import com.jfirer.jnet.common.buffer.IoBuffer;
import com.jfirer.redisserver.resp.Resp;

public class ResponseEncoder implements WriteProcessor<Resp>
{

    @Override
    public void write(Resp resp, ProcessorContext ctx)
    {
        BufferAllocator allocator = ctx.channelContext().channelConfig().getAllocator();
        IoBuffer        buffer    = allocator.directBuffer(128);
        Resp.write(resp, buffer);
        ctx.fireWrite(buffer);
    }
}
